#pragma once
#include <pthread.h>
#include <iostream>
#include "Mutex.hpp"
namespace LockModule
{
    class Mutex
    {
    public:
        Mutex(const Mutex &) = delete;
        const Mutex &operator=(const Mutex &) = delete;
        Mutex()
        {
            int n = pthread_mutex_init(&_lock, nullptr);
        }
        ~Mutex()
        {
            int n = pthread_mutex_destroy(&_lock);
        }
        void lock()
        {
            int n = pthread_mutex_lock(&_lock);
        }
        void unlock()
        {
            int n = pthread_mutex_unlock(&_lock);
        }
        pthread_mutex_t *LockPtr()
        {
            return &_lock;
        }

    private:
        pthread_mutex_t _lock;
    };
    class LockGuard
    {
    public:
        LockGuard(Mutex &mtx)
            : _mtx(mtx)
        {
            _mtx.lock();
        }
        ~LockGuard()
        {
            _mtx.unlock();
        }

    private:
        Mutex &_mtx;
    };
};
